import can
from typing import Optional, List
from common.common import Common
import common
import struct


# import queue
# from multiprocessing import Queue


class CanTool:

    def __init__(self, device: Optional[str], channel: Optional[str], bit_rate: Optional[int]):
        """
        初始化类时即创建总线对象
        param1：设备名
        param2：通道名
        param3：波特率
        """
        # 是否在初始化时创建对象基于项目而定
        try:
            self.__bus = can.interface.Bus(bustype=device, channel=channel, bitrate=bit_rate)
        except can.exceptions.CanInitializationError as e:
            print(f"CAN初始化失败: {e}")
            self.__bus = None
        # finally:
        # return

    def get_init(self):
        return self.__bus

    def send_data(self, recv_id: Optional[int], list_data: Optional[List[int]]):
        try:
            msg = can.Message(arbitration_id=recv_id,  # 此处传入整形
                              is_extended_id=False,  # 此处参数判断是否是扩展帧
                              data=list_data  # 此处参数传入一个纯整形的列表
                              )
            self.__bus.send(msg)
        except Exception as e:
            print(e)

    def can_recv(self, recv_id: Optional[float]):
        """
        接收到的报文中是否有需要的id
        para1：报文id
        """
        # recv_id = 0x123
        # can_filter = [{"can_id": recv_id, "can_mask": 0xFFFFFFFF, "extended": False}]
        # self.__bus.set_filters(can_filter)
        # state = self.__bus.status()
        # print("pcan总线状态：", state)

        message = self.__bus.recv(100)
        return message

    def bus_recv(self):
        # i = 0
        try:
            # while i <= 20:
            msg = self.__bus.recv(timeout=100)
            # i += 1
            # print(msg)
            # print(msg.arbitration_id)
            # print(msg.data[2])
            return msg
        except KeyboardInterrupt:
            pass

    # 丢弃可能在输出缓冲区排队的每一条信息
    def reset_tx_buffer(self):
        self.__bus.flush_tx_buffer()

    # 关闭总线
    def shutdown_bus(self):
        self.__bus.shutdown()

    # parse data segment
    @staticmethod
    def parse_data_seg(byte_l, byte_h):
        return byte_h << 8 | byte_l

    @staticmethod
    def byte_to_hex(byte_4, byte_5, byte_6, byte_7):
        hex_str_4 = hex(byte_4)[2:]
        if len(hex_str_4) == 1:
            hex_str_4 += '0'
        hex_str_5 = hex(byte_5)[2:]
        if len(hex_str_5) == 1:
            hex_str_5 += '0'
        hex_str_6 = hex(byte_6)[2:]
        if len(hex_str_6) == 1:
            hex_str_6 += '0'
        hex_str_7 = hex(byte_7)[2:]
        if len(hex_str_7) == 1:
            hex_str_7 += '0'
        return hex_str_4 + hex_str_5 + hex_str_6 + hex_str_7

    @staticmethod
    def parse_data_seg_float(byte_4, byte_5, byte_6, byte_7):
        hex_str = CanTool.byte_to_hex(byte_4, byte_5, byte_6, byte_7)
        # print(hex_str)
        byte_data = bytes.fromhex(hex_str)
        # ! network(＝big-endian）
        float_number = struct.unpack('<f', byte_data)[0]
        return round(float_number, 4)

    # parse recv data
    def parse_left_driver_data(self, msg, dict_data):
        if msg.data[2] == int('0x51', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                if data & (1 << (16 - 1)):
                    data -= 1 << 16
                v = (3.14 * 325 * 0.001 * data) / (60 * 36)
                v = round(v, 1)
                dict_data["left_driver_speed"] = v
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x52', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["left_driver_error_code"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x53', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["left_driver_torque"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x54', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["left_driver_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x55', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["left_driver_odo"] = data
            else:
                print("receive data failed")

    def parse_right_driver_data(self, msg, dict_data):
        if msg.data[2] == int('0x56', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                if data & (1 << (16 - 1)):
                    data -= 1 << 16
                v = (3.14 * 325 * 0.001 * data) / (60 * 36)
                v = round(v, 1)
                dict_data["right_driver_speed"] = v
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x57', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["right_driver_error_code"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x58', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["right_driver_torque"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x59', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["right_driver_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x5A', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["right_driver_odo"] = data
            else:
                print("receive data failed")

    def parse_increase_data(self, msg, dict_data):
        if msg.data[2] == int('0x5B', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_increase_pos"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x5C', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_increase_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x5D', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_increase_init_pos_adc"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x5E', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_increase_hall1_pos_adc"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x5F', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_increase_hall2_pos_adc"] = data
            else:
                print("receive data failed")

    def parse_cut1_data(self, msg, dict_data):
        if msg.data[2] == int('0x74', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                if data & (1 << (16 - 1)):
                    data -= 1 << 16
                dict_data["motor_cut1_speed"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x71', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut1_error_code"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x75', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut1_torque"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x76', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut1_current"] = data
            else:
                print("receive data failed")

    def parse_cut2_data(self, msg, dict_data):
        if msg.data[2] == int('0x77', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                if data & (1 << (16 - 1)):
                    data -= 1 << 16
                dict_data["motor_cut2_speed"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x72', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut2_error_code"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x78', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut2_torque"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x79', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut2_current"] = data
            else:
                print("receive data failed")

    def parse_cut3_data(self, msg, dict_data):
        if msg.data[2] == int('0x7A', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                if data & (1 << (16 - 1)):
                    data -= 1 << 16
                dict_data["motor_cut3_speed"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x73', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut3_error_code"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x7B', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut3_torque"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x7C', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["motor_cut3_current"] = data
            else:
                print("receive data failed")

    def parse_imu_data(self, msg, dict_data):
        if msg.data[2] == int('0x91', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_linear_v_x"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x92', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_linear_v_y"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x93', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_linear_v_z"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x94', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_angular_v_x"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x95', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_angular_v_y"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x96', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_angular_v_z"] = data
            else:
                print("receive data failed")

    def parse_imu_angle_data(self, msg, dict_data):
        if msg.data[2] == int('0x97', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_roll_angle"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x98', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_pitch_angle"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x99', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg_float(msg.data[4], msg.data[5], msg.data[6], msg.data[7])  # parse data
                dict_data["imu_heading_angle"] = data
            else:
                print("receive data failed")

    def parse_rain_ultrasonic_data(self, msg, dict_data):
        if msg.data[2] == int('0x9A', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_rain_adc"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x9B', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic1_dis"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x9C', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic2_dis"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x9D', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic3_dis"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x9E', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic4_dis"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0x9F', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic5_dis"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xA0', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic6_dis"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xA1', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic7_dis"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xA2', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["sensor_ultrasonic8_dis"] = data
            else:
                print("receive data failed")

    def parse_collide_data(self, msg, dict_data):
        if msg.data[2] == int('0xA3', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["collide1"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xA4', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["collide2"] = data
            else:
                print("receive data failed")

    def parse_bluetooth_data(self, msg, dict_data):
        if msg.data[2] == int('0xA5', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["bluetooth_status"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xA6', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["bluetooth_connect"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xA7', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["basestation_charge_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xA8', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["basestation_info_code"] = data
            else:
                print("receive data failed")

    def parse_light_data(self, msg, dict_data):
        if msg.data[2] == int('0xC1', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["fill_light1_current"] = data
            else:
                print("receive data failed")
        if msg.data[2] == int('0xC2', 16):  # check test item
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["fill_light2_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xC3', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["side_light_current_front_left"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xC4', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["side_light_current_front_right"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xC5', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["side_light_current_behind_left"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xC6', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["side_light_current_behind_right"] = data
            else:
                print("receive data failed")

    def parse_get_current(self, msg, dict_data):
        if msg.data[2] == int('0xC7', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["AI_board_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xC8', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["treble_alarm_5v_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xC9', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["ultrasonic_control_current"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xCA', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["parker_current"] = data
            else:
                print("receive data failed")

    def parse_battery_data(self, msg, dict_data):
        if msg.data[2] == int('0xCB', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["battery_vol"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xCC', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["battery_electricity"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xCD', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["battery_temperature"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xCE', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["battery_active"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xCF', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["battery_error_info"] = data
            else:
                print("receive data failed")

    def parse_key_lift_data(self, msg, dict_data):
        if msg.data[2] == int('0xD0', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["key"] = data
            else:
                print("receive data failed")
        elif msg.data[2] == int('0xD1', 16):
            if msg.data[3] == int('0x01', 16):  # check result
                data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
                dict_data["lift"] = data
            else:
                print("receive data failed")

    @staticmethod
    def parse_resp_data(msg, dict_data):
        for key, value in common.dict_response.items():
            if msg.data[2] == int(key, 16):
                if msg.data[3] == int('0x01', 16):  # check result
                    dict_data[msg.data[2]] = 1
                else:
                    dict_data[msg.data[2]] = 0
                break

    # parse can data(M4->APP)
    def can_data_parse(self, msg):
        dict_data = {}
        if msg.arbitration_id == int('0x227', 16):
            self.parse_left_driver_data(msg, dict_data)
            self.parse_right_driver_data(msg, dict_data)
            self.parse_increase_data(msg, dict_data)
            pass
        elif msg.arbitration_id == int('0x229', 16):
            self.parse_cut1_data(msg, dict_data)
            self.parse_cut2_data(msg, dict_data)
            self.parse_cut3_data(msg, dict_data)
            pass
        elif msg.arbitration_id == int('0x22B', 16):
            self.parse_imu_data(msg, dict_data)
            self.parse_imu_angle_data(msg, dict_data)
            self.parse_rain_ultrasonic_data(msg, dict_data)
            self.parse_collide_data(msg, dict_data)
            self.parse_bluetooth_data(msg, dict_data)
            pass
        elif msg.arbitration_id == int('0x22D', 16):
            self.parse_light_data(msg, dict_data)
            self.parse_get_current(msg, dict_data)
            self.parse_battery_data(msg, dict_data)
            self.parse_key_lift_data(msg, dict_data)
            pass
        # elif msg.arbitration_id == int('0x1801f4e7', 16):
        #     if msg.data[2] == int('0xc2', 16):  # check test item
        #         if msg.data[3] == int('0x01', 16):  # check result
        #             data = self.parse_data_seg(msg.data[4], msg.data[5]) # parse data
        #             dict_data["side_light_a"] = data
        #     elif msg.data[2] == int('0x00', 16):
        #         print("return data failed")
        # elif msg.arbitration_id == int('0x18f040e7', 16):
        #     if msg.data[2] == int('0x2c', 16):  # check test item
        #         if msg.data[3] == int('0x01', 16):  # check result
        #             data = self.parse_data_seg(msg.data[4], msg.data[5])  # parse data
        #             dict_data["fill_light_a"] = data
        #     elif msg.data[2] == int('0x00', 16):
        #         print("return data failed")
        elif msg.arbitration_id == int('0x225', 16):
            CanTool.parse_resp_data(msg, dict_data)
        return dict_data
